﻿using System;
using Cysharp.Threading.Tasks;
using JetBrains.Annotations;

namespace uMVP
{
    public abstract class PresenterBase : IPresenter
    {
        public async UniTask InitializeAsync()
        {
            await OnInitializeAsync();
        }

        public void Destroy()
        {
            OnDestroy();
        }
        
        
        public async UniTask OpenAsync()
        {
            await OnOpen();
        }
        
        public async UniTask CloseAsync()
        {
            await OnClose();
        }

        protected virtual UniTask OnInitializeAsync()
        {
            return UniTask.CompletedTask;
        }
        
        protected virtual void OnDestroy()
        {
        }

        protected virtual UniTask OnOpen()
        {
            return UniTask.CompletedTask;
        }
        
        protected virtual UniTask OnClose()
        {
            return UniTask.CompletedTask;
        }
    }

    public abstract class PresenterBase<TViewInterface> : PresenterBase where TViewInterface : class
    {
        protected TViewInterface View { get; }

        protected PresenterBase([NotNull] TViewInterface view)
        {
            View = view ?? throw new ArgumentNullException(nameof(view));
        }
    }
}